var express = require('express')
var router = express.Router()
var path = require('path')
var fs = require('fs')
const { getAll, getById, exec } = require('../db/index')

//引入保存文件的模块
let multer = require('multer')
const storage = multer.diskStorage({
  // 存储位置
  destination(req, file, callback) {
    callback(null, 'upload')
  },
  // 确定文件名
  filename(req, file, cb) {
    cb(null, Date.now() + file.originalname)
  },
})
// 得到multer对象  传入storage对象
const upload = multer({ storage })
// .................................................
const { debug } = require('../config/index')

//照片上传功能
router.post('/img', upload.single('image'), async (req, res) => {
  const url = 'http://localhost:3000/' + 'upload/' + req.file.filename
  res.json(url)
})

module.exports = router
